import React, { useState } from 'react';
import { axconst } from '@/shared/axconst';
import { AxStandardCardButtonType, AxStandardCardFilterType } from '@/components/AxList/AxStandardLayout/data.d';
import { AxStandardWideList } from '@/components/AxList/AxStandardWideList';
import Import from './components/import';
import Material from './components/material';

const Index: React.FC<any> = props => {
    const [importVisible, setImportVisible] = useState(false);
    const [expandedRowKeys, setExpandedRowKeys] = useState(['1']);
    /** 配置列 */
    const columns = [
        {
            title: 'CAS名称',
            dataIndex: 'cas',
            width: axconst.width.cas,
        },
        {
            title: 'CAS编码',
            dataIndex: 'casCode',
            width: axconst.width.casCode,
        },
        {
            title: '性状',
            dataIndex: 'character',
            width: axconst.width.fouronly,
        },
        {
            title: '计量单位',
            dataIndex: 'unit',
            width: axconst.width.fouronly,
        },
        {
            title: '最大库存量',
            dataIndex: 'maxCount',
            width: axconst.width.five,
        },
    ];

    /** 配置操作按钮 */
    const button: AxStandardCardButtonType[] = [
        {
            text: '上传物资',
            icon: 'import',
            onClick: () => setImportVisible(true),
        },
        {
            text: '提交审核',
            icon: 'plus',
            // onClick: () => setCreateVisible(true),
        }
    ];

    const filter: AxStandardCardFilterType[] = []

    const importProps = {
        visible: importVisible,
        handleVisible: setImportVisible,
    };

    const handleExpandedRowsChange = (expandedRows: any) => {
        setExpandedRowKeys(expandedRows);
    };

    return (
        <>
            <AxStandardWideList
                columns={columns}
                button={button}
                filter={filter}
                data={{...axconst.data}}
                checkboxModel={false}
                expandedRowKeys={expandedRowKeys}
                onExpandedRowsChange={handleExpandedRowsChange}
                expandedRowRender={(record: any) => (
                    <Material />
                )}
            />
            {importVisible && <Import {...importProps} />}
        </>
    );
};

export default Index;
